﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApAPPUtilities
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Implementation;
using Tecnomatix.Engineering.Olp;
using Tecnomatix.Engineering.Olp.RoboticParameters;


namespace DnProcessSimulateCommands;

public class CApAPPUtilities
{
  private static ITxCommand m_command;
  private static TxCommandPrivateDataStorage m_registryManager;
  private const string FINE_ZONE_STR = "fine";

  internal static void InitRegistryManager(ITxCommand command)
  {
    CApAPPUtilities.m_command = command;
    CApAPPUtilities.m_registryManager = new TxCommandPrivateDataStorage(CApAPPUtilities.m_command);
  }

  internal static TxCommandPrivateDataStorage GetRegistryManager()
  {
    return CApAPPUtilities.m_registryManager;
  }

  public static List<List<string>> GetAllRobotsZone(
    ITxRobot i_robot,
    ITxOperation operation,
    List<string> zoneParameterNames,
    TxMotionType motionType)
  {
    List<List<string>> allRobotsZone = new List<List<string>>();
    foreach (string zoneParameterName in zoneParameterNames)
    {
      List<string> zoneParameterValues = CApAPPUtilities.GetAllowableZoneParameterValues(i_robot, operation, zoneParameterName, motionType);
      if (zoneParameterValues.Count == 0)
        zoneParameterValues.Add("");
      allRobotsZone.Add(zoneParameterValues);
    }
    if (allRobotsZone.Count < 3)
    {
      for (int count = allRobotsZone.Count; count < 3; ++count)
        allRobotsZone.Add(new List<string>() { "" });
    }
    return allRobotsZone;
  }

  internal static List<string> GetAllowableZoneParameterValues(
    ITxRobot robot,
    ITxOperation roboticOperation,
    string zoneString,
    TxMotionType motionType)
  {
    List<string> zoneParameterValues = new List<string>();
    if (robot != null)
    {
      if (CApAPPUtilities.IsRobotSetWithDefaultController(robot))
      {
        zoneParameterValues.Add("fine");
        zoneParameterValues.Add("medium");
        zoneParameterValues.Add("coarse");
        zoneParameterValues.Add("nodecel");
      }
      else if (CApAPPUtilities.IsRobotSetWithVKRCController(robot))
      {
        zoneParameterValues.Add("0 %");
        zoneParameterValues.Add("5 %");
        zoneParameterValues.Add("10 %");
        zoneParameterValues.Add("15 %");
        zoneParameterValues.Add("20 %");
        zoneParameterValues.Add("25 %");
        zoneParameterValues.Add("30 %");
        zoneParameterValues.Add("35 %");
        zoneParameterValues.Add("40 %");
        zoneParameterValues.Add("45 %");
        zoneParameterValues.Add("50 %");
        zoneParameterValues.Add("60 %");
        zoneParameterValues.Add("70 %");
        zoneParameterValues.Add("80 %");
        zoneParameterValues.Add("90 %");
        zoneParameterValues.Add("100 %");
      }
      else if (CApAPPUtilities.IsRobotSetWithDensoController(robot))
      {
        zoneParameterValues.Add("0");
        zoneParameterValues.Add("1");
        zoneParameterValues.Add("2");
        zoneParameterValues.Add("3");
        zoneParameterValues.Add("4");
        zoneParameterValues.Add("5");
        zoneParameterValues.Add("10");
        zoneParameterValues.Add("20");
        zoneParameterValues.Add("30");
        zoneParameterValues.Add("40");
        zoneParameterValues.Add("50");
        zoneParameterValues.Add("60");
        zoneParameterValues.Add("70");
        zoneParameterValues.Add("80");
        zoneParameterValues.Add("90");
        zoneParameterValues.Add("100");
        zoneParameterValues.Add("150");
        zoneParameterValues.Add("200");
      }
      else
      {
        TxOperationRoot operationRoot = TxApplication.ActiveDocument.OperationRoot;
        new TxWeldOperationCreationData().Robot = robot;
        TxRoboticViaLocationOperation locationOperation = CApAPPUtilities.CreateViaLocationOperation(roboticOperation);
        if (TxRoboticViaLocationOperation.op_Inequality(locationOperation, (ITxObject) null) && zoneString != "")
        {
          TxRoboticIntParam txRoboticIntParam = new TxRoboticIntParam("RRS_MOTION_TYPE", (int) motionType);
          locationOperation.SetParameter((TxRoboticParam) txRoboticIntParam);
          string name = robot.Controller.Name;
          TxPathEditorToDotNetGap editorToDotNetGap = new TxPathEditorToDotNetGap();
          string str1 = $"{name}_{zoneString}";
          string globalIdString = TxEngineeringDataInternal.GetGlobalIdString((ITxObject) locationOperation);
          string[] strArray = new string[50];
          editorToDotNetGap.GetComplexComboItems(str1, ref strArray, globalIdString);
          if (strArray != null)
          {
            for (int index = 0; index < strArray.Length; ++index)
            {
              if (strArray[index] != null)
                zoneParameterValues.Add(strArray[index]);
            }
            string str2 = "More...";
            zoneParameterValues.Remove(str2);
          }
        }
        locationOperation.Delete();
      }
      int num = 0;
      while ((num = zoneParameterValues.IndexOf("")) != -1)
        zoneParameterValues.Remove("");
      if (CApAPPUtilities.IsRobotSetWithYaskawaController(robot))
      {
        string str = zoneParameterValues[0];
        zoneParameterValues.RemoveAt(0);
        zoneParameterValues.Add(str);
      }
    }
    return zoneParameterValues;
  }

  public static List<List<string>> ConvertZoneInZoneList(string[][] iZones)
  {
    List<List<string>> stringListList = new List<List<string>>();
    int index1 = 0;
    if (iZones.Length != 0)
    {
      for (; index1 < iZones[0].Length; ++index1)
      {
        List<string> stringList = new List<string>();
        for (int index2 = 0; index2 < iZones.Length; ++index2)
          stringList.Add(iZones[index2][index1]);
        stringListList.Add(stringList);
      }
    }
    return stringListList;
  }

  public static List<List<string>> ConvertZoneInZoneList(ArrayList iZonesArrayList)
  {
    List<List<string>> stringListList = new List<List<string>>();
    int index1 = 0;
    if (iZonesArrayList.Count != 0)
    {
      for (ArrayList iZonesArray = iZonesArrayList[index1] as ArrayList; index1 < iZonesArray.Count; ++index1)
      {
        List<string> stringList = new List<string>();
        for (int index2 = 0; index2 < iZonesArrayList.Count; ++index2)
        {
          iZonesArray = iZonesArrayList[index2] as ArrayList;
          stringList.Add(iZonesArray[index1] as string);
        }
        stringListList.Add(stringList);
      }
    }
    return stringListList;
  }

  public static int GetZoneIndex(string iZone, List<string> zoneList)
  {
    int zoneIndex = -1;
    for (int index = 0; index < zoneList.Count; ++index)
    {
      if (zoneList[index] == iZone)
      {
        zoneIndex = index;
        break;
      }
    }
    return zoneIndex;
  }

  public static List<string> GetZoneParameters(ITxRobot robot, ITxOperation robotOperation)
  {
    List<string> zoneParameters = new List<string>();
    if (robot != null)
    {
      if (CApAPPUtilities.IsRobotSetWithDefaultController(robot) || CApAPPUtilities.IsRobotSetWithDensoController(robot) || CApAPPUtilities.GetRobotControllerParametersHandler(robotOperation) == null)
        zoneParameters.Add("Zone");
      else if (CApAPPUtilities.IsRobotSetWithVKRCController(robot))
        zoneParameters.Add("Ve");
      else if (CApAPPUtilities.IsRobotSetWithYaskawaController(robot))
      {
        zoneParameters.Add("Level");
      }
      else
      {
        ITxOlpRobotControllerParametersHandler parametersHandler = CApAPPUtilities.GetRobotControllerParametersHandler(robotOperation);
        string[] strArray = (string[]) null;
        if (parametersHandler != null)
          strArray = parametersHandler.GetFlybyParametersNames(robot as TxRobot);
        if (strArray != null)
        {
          for (int index = 0; index < strArray.Length; ++index)
          {
            if (strArray[index] != null)
              zoneParameters.Add(strArray[index]);
          }
        }
      }
    }
    return zoneParameters;
  }

  internal static ITxOlpRobotControllerParametersHandler GetRobotControllerParametersHandler(
    ITxOperation operation)
  {
    return new TxOlpControllerUtilities().InitAndGetRobotControllerParametersHandlerInstance(operation);
  }

  internal static TxRoboticViaLocationOperation CreateViaLocationOperation(
    ITxOperation roboticOperation)
  {
    TxRoboticViaLocationOperation locationOperation = (TxRoboticViaLocationOperation) null;
    TxRoboticViaLocationOperationCreationData operationCreationData = new TxRoboticViaLocationOperationCreationData();
    switch (roboticOperation)
    {
      case ITxWeldOperation _:
        locationOperation = ((ITxRoboticViaLocationOperationCreation) (roboticOperation as ITxWeldOperation)).CreateRoboticViaLocationOperation(operationCreationData);
        break;
      case ITxContinuousOperation _:
        locationOperation = ((ITxRoboticViaLocationOperationCreation) (roboticOperation as ITxContinuousOperation)).CreateRoboticViaLocationOperation(operationCreationData);
        break;
      case TxGenericRoboticOperation _:
        locationOperation = ((TxBaseGenericRoboticOperation) (roboticOperation as TxGenericRoboticOperation)).CreateRoboticViaLocationOperation(operationCreationData);
        break;
    }
    return locationOperation;
  }

  internal static ITxOperation CopyOperation(ITxOperation txOp)
  {
    ITxObject key = (ITxObject) null;
    ITxObjectCollection objectCollection1 = (ITxObjectCollection) null;
    ITxOperation itxOperation = (ITxOperation) null;
    ITxObjectCollection objectCollection2;
    switch (txOp)
    {
      case TxTcDiscreteOperation _:
      case TxTcContinuousOperation _:
        objectCollection2 = txOp as ITxObjectCollection;
        break;
      default:
        objectCollection2 = ((ITxObject) txOp).Collection;
        break;
    }
    switch (objectCollection2)
    {
      case TxCompoundOperation _:
      case TxOperationRoot _:
        key = (ITxObject) txOp;
        objectCollection1 = objectCollection2;
        break;
      case ITxTcOperation _:
        key = (ITxObject) objectCollection2;
        objectCollection1 = ((ITxObject) objectCollection2).Collection;
        break;
      case TxTcActivity _:
        TxOperationRoot operationRoot = TxApplication.ActiveDocument.OperationRoot;
        if (TxOperationRoot.op_Inequality(operationRoot, (ITxObject) null))
        {
          ITxObject itxObject = (ITxObject) objectCollection2;
          bool flag = false;
          while (itxObject != operationRoot && !flag)
          {
            itxObject = (ITxObject) itxObject.Collection;
            if (itxObject is ITxTcOperation)
            {
              flag = true;
              key = itxObject;
              objectCollection1 = itxObject.Collection;
            }
          }
          break;
        }
        break;
    }
    if (key != null && objectCollection1 != null)
    {
      TxObjectList txObjectList = new TxObjectList();
      Hashtable hashtable = new Hashtable();
      ((Collection<ITxObject>) txObjectList).Add(key);
      if (objectCollection1.CanPasteList(txObjectList))
      {
        objectCollection1.Paste(txObjectList, ref hashtable);
        itxOperation = (ITxOperation) hashtable[(object) key];
      }
    }
    return itxOperation;
  }

  internal static bool GetParameterType(
    ITxRobot robot,
    string parameterName,
    out CApAPPUtilities.ParameterType paramType)
  {
    bool parameterType1 = false;
    CApAPPUtilities.ParameterType parameterType2 = CApAPPUtilities.ParameterType.Combo;
    if (CApAPPUtilities.IsRobotSetWithDefaultController(robot) || CApAPPUtilities.IsRobotSetWithVKRCController(robot) || CApAPPUtilities.IsRobotSetWithDensoController(robot))
    {
      parameterType1 = true;
    }
    else
    {
      TxOlpRoboticParametersManager parametersManager = new TxOlpRoboticParametersManager(robot.Controller.Name);
      parametersManager.SetManager();
      string propertyId = parametersManager.GetPropertyId(parameterName);
      Type valueType = parametersManager.GetValueType(propertyId);
      if (valueType != (Type) null)
      {
        if (valueType == typeof (double))
          parameterType2 = CApAPPUtilities.ParameterType.Double;
        parameterType1 = true;
      }
    }
    paramType = parameterType2;
    return parameterType1;
  }

  internal static ArrayList GetLocationZoneParametersValues(
    ITxRobot robot,
    ITxRoboticOperation robotOperation,
    ITxRoboticLocationOperation loc)
  {
    ArrayList parametersValues = new ArrayList();
    if (CApAPPUtilities.IsRobotSetWithDefaultController(robot))
    {
      if (((ITxRoboticOperation) loc).GetParameter("RRS_ZONE_NAME") is TxRoboticStringParam parameter)
      {
        string str = parameter.Value;
        if (str != null && str != "")
          parametersValues.Add((object) str);
      }
    }
    else
    {
      string name = robot.Controller.Name;
      List<string> zoneParameters = CApAPPUtilities.GetZoneParameters(robot, (ITxOperation) robotOperation);
      TxPathEditorToDotNetGap editorToDotNetGap = new TxPathEditorToDotNetGap();
      string globalIdString = TxEngineeringDataInternal.GetGlobalIdString((ITxObject) loc);
      for (int index = 0; index < zoneParameters.Count; ++index)
      {
        string str1 = zoneParameters[index];
        string str2 = $"{name}_{str1}";
        string str3 = "";
        editorToDotNetGap.GetComplexRepresentation(ref str3, globalIdString, str2);
        if (str3 != null)
          str3 = str3.Trim();
        parametersValues.Add((object) str3);
      }
    }
    return parametersValues;
  }

  internal static void SetLocationZoneParametersValues(
    ITxRobot robot,
    ITxRoboticOperation robotOperation,
    ITxRoboticLocationOperation loc,
    ArrayList zoneValues)
  {
    if (CApAPPUtilities.IsRobotSetWithDefaultController(robot))
    {
      if (zoneValues.Count != 1)
        return;
      TxRoboticStringParam roboticStringParam = new TxRoboticStringParam("RRS_ZONE_NAME", zoneValues[0] as string);
      ((ITxRoboticOperation) loc).SetParameter((TxRoboticParam) roboticStringParam);
    }
    else
    {
      string name = robot.Controller.Name;
      List<string> zoneParameters = CApAPPUtilities.GetZoneParameters(robot, (ITxOperation) robotOperation);
      TxPathEditorToDotNetGap editorToDotNetGap = new TxPathEditorToDotNetGap();
      string globalIdString = TxEngineeringDataInternal.GetGlobalIdString((ITxObject) loc);
      for (int index = 0; index < zoneParameters.Count; ++index)
      {
        string str1 = zoneParameters[index];
        string str2 = $"{name}_{str1}";
        string zoneValue = zoneValues[index] as string;
        bool flag = false;
        editorToDotNetGap.HasComplexRepresentation(str2, globalIdString, ref flag);
        if (flag)
          editorToDotNetGap.OnComplexValueChanged(str2, zoneValue, globalIdString);
      }
    }
  }

  internal static bool ArraysAreEqual(ArrayList arr1, ArrayList arr2)
  {
    bool flag = true;
    if (arr1.Count != arr2.Count)
      flag = false;
    for (int index = 0; index < arr1.Count & flag; ++index)
    {
      if (!arr1[index].Equals(arr2[index]))
        flag = false;
    }
    return flag;
  }

  internal static bool IsRobotSetWithDefaultController(ITxRobot robot)
  {
    bool flag = false;
    if (robot.Controller.Name == "default")
      flag = true;
    else if ((ITxRoboticControllerServices) new TxOlpControllerUtilities().GetInterfaceImplementationFromController(robot.Controller.Name, typeof (ITxRoboticControllerServices), typeof (TxControllerAttribute), "ControllerName") == null)
      flag = true;
    return flag;
  }

  internal static bool IsRobotSetWithVKRCController(ITxRobot robot)
  {
    return robot.Controller.Name == "Kuka-Vkrc";
  }

  internal static bool IsRobotSetWithDensoController(ITxRobot robot)
  {
    return robot.Controller.Name == "Denso-PacScript";
  }

  internal static bool IsRobotSetWithYaskawaController(ITxRobot robot)
  {
    return robot.Controller.Name == "Yaskawa-Inform";
  }

  private static bool IsZoneSetValid(
    TxRobot robot,
    ArrayList zonesList,
    out CApAPPUtilities.ZoneErrStatus status)
  {
    bool flag1 = true;
    status = CApAPPUtilities.ZoneErrStatus.OK;
    if (zonesList.Count < 2)
    {
      flag1 = false;
      status = CApAPPUtilities.ZoneErrStatus.SingleZone;
    }
    if (flag1)
    {
      ArrayList arrayList = new ArrayList();
      for (int index1 = 0; index1 < zonesList.Count & flag1; ++index1)
      {
        ArrayList zones = zonesList[index1] as ArrayList;
        string str = "";
        for (int index2 = 0; index2 < zones.Count; ++index2)
          str += zones[index2] as string;
        if (!arrayList.Contains((object) str))
        {
          arrayList.Add((object) str);
        }
        else
        {
          flag1 = false;
          status = CApAPPUtilities.ZoneErrStatus.DuplicateZones;
        }
      }
    }
    if (flag1 && (zonesList[0] as ArrayList).Count == 1 && CApAPPUtilities.IsRobotSetWithDefaultController((ITxRobot) robot))
    {
      bool flag2 = false;
      for (int index = 0; index < zonesList.Count && !flag2; ++index)
      {
        string str = (zonesList[index] as ArrayList)[0] as string;
        if (str == "fine" || str == "FINE")
          flag2 = true;
      }
      if (!flag2)
      {
        flag1 = false;
        status = CApAPPUtilities.ZoneErrStatus.NoFineZone;
      }
    }
    return flag1;
  }

  private static bool IsValidLocation(ITxObject obj)
  {
    switch (obj)
    {
      case TxObjectFlowLocationOperation _:
      case TxWeldLocationOperation _:
      case TxRoboticViaLocationOperation _:
        return true;
      default:
        return obj is TxRoboticSeamOperation;
    }
  }

  private static bool IsValidOperation(ITxObject obj)
  {
    bool flag;
    switch (obj)
    {
      case TxObjectFlowOperation _:
        flag = (obj as TxObjectFlowOperation).SimulatedObject != null;
        break;
      case ITxWeldOperation _:
        flag = ((ITxRoboticOrderedCompoundOperation) (obj as ITxWeldOperation)).Robot != null && (obj as ITxWeldOperation).Tool != null;
        if (flag)
        {
          flag = !CApAPPUtilities.IsSuperComponent((ITxObject) (obj as ITxWeldOperation).Tool);
          break;
        }
        break;
      case ITxContinuousOperation _:
        flag = ((ITxRoboticOrderedCompoundOperation) (obj as ITxContinuousOperation)).Robot != null && (obj as ITxContinuousOperation).Tool != null;
        if (flag)
        {
          flag = !CApAPPUtilities.IsSuperComponent((obj as ITxContinuousOperation).Tool);
          break;
        }
        break;
      default:
        flag = false;
        break;
    }
    return flag;
  }

  private static bool IsSuperComponent(ITxObject obj)
  {
    bool flag = false;
    if (obj is ITxComponent itxComponent)
      flag = itxComponent.IsSuperComponent;
    return flag;
  }

  public static bool IsDeviceExternalToRobot(ITxDevice device, ITxRobot robot)
  {
    bool robot1 = false;
    TxObjectList externalAxes = robot.ExternalAxes;
    TxObjectList drivingJoints = device.DrivingJoints;
    if (((Collection<ITxObject>) externalAxes).Count > 0 && ((Collection<ITxObject>) drivingJoints).Count > 0)
    {
      foreach (TxJoint txJoint in (Collection<ITxObject>) drivingJoints)
      {
        if (((Collection<ITxObject>) externalAxes).Contains((ITxObject) txJoint))
        {
          robot1 = true;
          break;
        }
      }
    }
    return robot1;
  }

  public static bool PosesAreEqual(TxPoseData firstPoseData, TxPoseData secondPoseData)
  {
    bool flag = true;
    if (firstPoseData.JointValues.Count != secondPoseData.JointValues.Count)
      flag = false;
    for (int index = 0; index < firstPoseData.JointValues.Count & flag; ++index)
      flag = (double) firstPoseData.JointValues[index] == (double) secondPoseData.JointValues[index];
    return flag;
  }

  public static bool PosesAreEquivalent(TxPoseData firstPoseData, TxPoseData secondPoseData)
  {
    bool flag = true;
    double num1 = 0.01;
    double num2 = 2.0 * Math.PI;
    if (firstPoseData.JointValues.Count != secondPoseData.JointValues.Count)
      flag = false;
    for (int index = 0; index < firstPoseData.JointValues.Count & flag; ++index)
    {
      double num3 = (double) firstPoseData.JointValues[index] % num2;
      double num4 = (double) secondPoseData.JointValues[index] % num2;
      flag = num3 + num1 >= num4 && num3 - num1 <= num4;
    }
    return flag;
  }

  public static ITxComponent GetAttachedTool(TxRobot robot, ITxOperation oper)
  {
    ITxComponent attachedTool = (ITxComponent) null;
    if (oper is ITxContinuousOperation)
      attachedTool = (oper as ITxContinuousOperation).Tool as ITxComponent;
    else if (oper is ITxWeldOperation)
      attachedTool = (oper as ITxWeldOperation).Gun as ITxComponent;
    if (attachedTool == null)
    {
      TxObjectList mountedTools = robot.MountedTools;
      foreach (ITxObject itxObject in (Collection<ITxObject>) mountedTools)
      {
        if (itxObject is ITxGun)
        {
          attachedTool = itxObject as ITxComponent;
          break;
        }
      }
      if (attachedTool == null && ((Collection<ITxObject>) mountedTools).Count > 0)
        attachedTool = ((Collection<ITxObject>) mountedTools)[0] as ITxComponent;
    }
    if (attachedTool == null && (oper as ITxRoboticOperation).IsMountedWorkpieceOperation)
    {
      if (((Collection<ITxObject>) robot.MountedTools).Count > 0)
      {
        attachedTool = ((Collection<ITxObject>) robot.MountedTools)[0] as ITxComponent;
      }
      else
      {
        TxObjectList links = robot.Links;
        ITxObject itxObject = ((Collection<ITxObject>) links)[((Collection<ITxObject>) links).Count - 1];
        TxTypeFilter txTypeFilter = new TxTypeFilter();
        txTypeFilter.AddIncludedType(typeof (ITxComponent));
        TxObjectList attachmentDescendants = (itxObject as ITxLocatableObject).GetDirectAttachmentDescendants((ITxTypeFilter) txTypeFilter);
        if (((Collection<ITxObject>) attachmentDescendants).Count > 0)
          attachedTool = (ITxComponent) ((Collection<ITxObject>) attachmentDescendants)[0];
      }
    }
    return attachedTool;
  }

  public static TxObjectList GetOperationLocations(ITxOperation operation)
  {
    TxObjectList operationLocations = new TxObjectList();
    for (int index = 0; index < ((ITxObjectCollection) (operation as ITxOrderedObjectCollection)).Count; ++index)
    {
      ITxObject childAt = (operation as ITxOrderedObjectCollection).GetChildAt(index);
      if (childAt != null && (!(childAt is TxWeldLocationOperation) || (childAt as TxWeldLocationOperation).IsProjected))
        ((Collection<ITxObject>) operationLocations).Add(childAt);
    }
    return operationLocations;
  }

  public static string GetTimeText(double timeInSecond)
  {
    timeInSecond = Math.Truncate(timeInSecond);
    string str1 = "0:";
    string str2 = "00:";
    string str3;
    if (timeInSecond < 60.0)
    {
      str3 = timeInSecond >= 10.0 ? timeInSecond.ToString() ?? "" : "0" + timeInSecond.ToString();
    }
    else
    {
      int num1 = 0;
      if (timeInSecond > 3600.0)
      {
        num1 = (int) Math.Truncate(timeInSecond / 3600.0);
        str1 = num1.ToString() + ":";
      }
      int num2 = (int) Math.Truncate((timeInSecond - (double) (num1 * 3600)) / 60.0);
      str2 = num2 >= 10 ? num2.ToString() + ":" : $"0{num2.ToString()}:";
      double num3 = timeInSecond - (double) (num1 * 3600 + num2 * 60);
      str3 = num3 >= 10.0 ? num3.ToString() ?? "" : "0" + num3.ToString();
    }
    return str1 + str2 + str3;
  }

  public static bool IsRobotConnectedToRCS(ITxRobot robot)
  {
    bool rcs = false;
    if (CApAPPUtilities.CanUseRCSForRobot(robot))
    {
      TxRRSServicesProvider servicesProvider;
      try
      {
        servicesProvider = new TxRRSServicesProvider(robot as TxRobot);
      }
      catch (TxRRSCanNotInitializeRcsException ex)
      {
        servicesProvider = (TxRRSServicesProvider) null;
      }
      if (servicesProvider != null)
        rcs = !robot.IsRCSTurnedOffForSimulationActions;
    }
    return rcs;
  }

  public static bool CanUseRCSForRobot(ITxRobot robot)
  {
    bool flag = false;
    if (robot != null)
    {
      ITxRobotController controller = (ITxRobotController) robot.Controller;
      if (controller != null && controller.Name != "" && controller.Name != "default")
        flag = true;
      if (flag)
        flag = !robot.IsRCSTurnedOffForSimulationActions && !robot.IsRCSTurnedOffForNonSimulationActions;
    }
    return flag;
  }

  public static bool IsKineoForAppPathPlanningAvailable()
  {
    bool flag = false;
    return TxRose.AutomaticPathPlanningIsKineoForAppPathPlanningAvailable(ref flag) & flag;
  }

  public static bool IsKineoForAppTrajectoryPlanningAvailable()
  {
    bool flag = false;
    return TxRose.AutomaticPathPlanningIsKineoForAppTrajectoryPlanningAvailable(ref flag) & flag;
  }

  internal enum ZoneErrStatus
  {
    OK,
    SingleZone,
    DuplicateZones,
    InvalidZones,
    NoFineZone,
  }

  internal enum ParameterType
  {
    Combo,
    Double,
  }
}
